var reverse = function (x) {
  var max = 2 ** 31 - 1;
  var min = -(2 ** 31);
  var isNegative = x < 0;
  var str = `${Math.abs(x)}`;
  var result = Number(str.split("").reverse().join(""));
  result = isNegative ? -result : result;

  if (result > max) {
    return 0;
  }
  if (result < min) {
    return 0;
  }
  return result;
};
